package com.godGuang.consultation.service.impl;

import java.util.List;

import com.godGuang.common.core.domain.Result;
import com.godGuang.common.core.web.page.TableDataInfo;
import com.godGuang.common.system.domain.SysDictData;
import com.godGuang.consultation.domain.DoctorReq;
import com.godGuang.consultation.remote.ConsultationDictFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.godGuang.consultation.mapper.DoctorMapper;
import com.godGuang.consultation.domain.Doctor;
import com.godGuang.consultation.service.IDoctorService;

/**
 * 问诊Service业务层处理
 *
 * @author godGuang
 * @date 2024-01-11
 */
@Service
public class DoctorServiceImpl implements IDoctorService
{
    @Autowired
    private DoctorMapper doctorMapper;

    @Autowired
    private ConsultationDictFeign consultationDictFeign;

    /**
     * 查询问诊
     *
     * @param id 问诊主键
     * @return 问诊
     */
    @Override
    public Doctor selectDoctorById(Long id)
    {
        return doctorMapper.selectDoctorById(id);
    }

    /**
     * 查询问诊列表
     *
     * @param doctor 问诊
     * @return 问诊
     */
    @Override
    public List<Doctor> selectDoctorList(Doctor doctor)
    {
        String doctorDepartments = doctor.getDoctorDepartments();
        if (doctorDepartments==null){
            return doctorMapper.selectDoctorList(doctor);
        }
        SysDictData sysDictData = new SysDictData();
        sysDictData.setDictLabel(doctorDepartments);
        Result<TableDataInfo<SysDictData>> list = consultationDictFeign.list(sysDictData);
        if (list.getCode()==Result.FAIL){
            throw new RuntimeException("获取数据失败");
        }
        if (list.getData().getRows()==null){
            throw new RuntimeException("获取数据失败");
        }
        TableDataInfo<SysDictData> data = list.getData();
        List<SysDictData> rows = data.getRows();
        Doctor doctorInfo = new Doctor();
        for (SysDictData row : rows) {
            doctorInfo.setDoctorDepartments(row.getDictValue());
        }
        return doctorMapper.selectDoctorList(doctorInfo);
    }

    /**
     * 新增问诊
     *
     * @param doctor 问诊
     * @return 结果
     */
    @Override
    public int insertDoctor(Doctor doctor)
    {
        return doctorMapper.insertDoctor(doctor);
    }

    /**
     * 修改问诊
     *
     * @param doctor 问诊
     * @return 结果
     */
    @Override
    public int updateDoctor(Doctor doctor)
    {
        return doctorMapper.updateDoctor(doctor);
    }

    /**
     * 批量删除问诊
     *
     * @param ids 需要删除的问诊主键
     * @return 结果
     */
    @Override
    public int deleteDoctorByIds(Long[] ids)
    {
        return doctorMapper.deleteDoctorByIds(ids);
    }

    /**
     * 删除问诊信息
     *
     * @param id 问诊主键
     * @return 结果
     */
    @Override
    public int deleteDoctorById(Long id)
    {
        return doctorMapper.deleteDoctorById(id);
    }

    @Override
    public List<Doctor> doctorFindById(DoctorReq doctorReq) {
        return doctorMapper.doctorFindById(doctorReq);
    }
}
